package com.hctforgreen.greenservice.machineManager.impl;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.machineManager.MachineBase;
import com.hctforgreen.greenservice.model.LocationEntity;
import com.hctforgreen.greenservice.model.PwdEntity;
import com.hctforgreen.greenservice.model.SYHotWaterMachineEntity;
import com.hctforgreen.greenservice.ui.adapter.SpinnerStringsAdapter;
import com.hctforgreen.greenservice.utils.HctResult;
import com.hctforgreen.greenservice.utils.Utils;
/**
 * 商用热水机-地暖工程
 * @author 390694
 *
 */
public class ComFloorHeat  extends MachineBase{

	private View layout_FloorHeat;
	
	private Spinner spinner_ground_surface_layer_structur;
	private Spinner spinner_heating_form;
	private Spinner spinner_heating_pipe_laying_method;
	private Spinner spinner_floor_heating_tube_outer_diameter;
	private Spinner spinner_floor_heating_tube_spacing;
	private Spinner spinner_built_area;
	private Spinner spinner_unit_installation_position;
	private Spinner spinner_engineering_tank_capacity;
	private Spinner spinner_expansion_volume;
	
	
	/**
	 * // 多联机：内机与内机的最大落差；热水机：使用水源;商用热水机：使用水源
	 */
	private String inDropHeight;
	/**
	 * 商用热水机：是否安装回水装置// 多联机：外机最大风管长度；热水机：使用人数
	 */
	private String tubeLength;
	/**
	 * // 多联机：内机与外机的最大落差；热水机：冷媒连接管||商用热水机：机组与水箱落差
	 */
	private String dropHeight;
	/**
	 * // 热水机： 配套水箱 || 商用热水机：水箱大小
	 */
	private String matchWaterbox;
	/**
	 * // 多联机：内机到外机连接管长度；热水机：水箱安装位置 ||商用热水机：机组安装位置
	 */
	private String ioConnectionLength;
	/**
	 * // 多联机：外机总线径；热水机：户型面积
	 */
	private String diameter;	
	/**
	 * // 安装位置
	 */
	private String installationSite;
	/**
	 * // 建筑面积
	 */
	private String constructionArea;
	/**
	 * // 多联机：冷媒追加量；热水机：热水用水点;
	 */
	private String addCoolantWeight;
	
	
	/**
	 * 商用热水机 使用场所
	 */
	private String operationSite;

	//商用热水机地暖工程特有属性实体类，关联提示页面用
	public SYHotWaterMachineEntity syHotWaterMachineEntity ;


	public void setOperationSite(String operationSite) {
		this.operationSite = operationSite;
		syHotWaterMachineEntity.setOperationSite(operationSite);
	}
	
	
	public ComFloorHeat(Activity context) {
		super(context);
		initView();
		syHotWaterMachineEntity =new SYHotWaterMachineEntity();
	}

	
	@Override
	public void initView() {
		layout_FloorHeat = findViewById(R.id.layout_FloorHeat);
		
		spinner_heating_form = (Spinner) findViewById(R.id.spinner_heating_form);
		spinner_ground_surface_layer_structur = (Spinner) findViewById(R.id.spinner_ground_surface_layer_structur);
		spinner_heating_pipe_laying_method = (Spinner) findViewById(R.id.spinner_heating_pipe_laying_method);
		spinner_floor_heating_tube_outer_diameter = (Spinner) findViewById(R.id.spinner_floor_heating_tube_outer_diameter);
		spinner_floor_heating_tube_spacing = (Spinner) findViewById(R.id.spinner_floor_heating_tube_spacing);
		spinner_built_area = (Spinner) findViewById(R.id.spinner_built_area);
		spinner_unit_installation_position = (Spinner) findViewById(R.id.spinner_unit_installation_position);
		spinner_engineering_tank_capacity = (Spinner) findViewById(R.id.spinner_engineering_tank_capacity);
		spinner_expansion_volume = (Spinner) findViewById(R.id.spinner_expansion_volume);
	}

	@Override
	public void showView() {
		layout_FloorHeat.setVisibility(View.VISIBLE);
		initHeating_form();
		initGround_surface_layer_structur();
		initHeating_pipe_laying_method();
		initFloor_heating_tube_outer_diameter();
		initFloor_heating_tube_spacing();
		initBuilt_area();
		initFHUnit_installation_position();
		initEngineering_tank_capacity();
		initExpansion_volume();
	}

	@Override
	public void hideView() {
		layout_FloorHeat.setVisibility(View.GONE);
		
	}

	
	
	@Override
	public boolean validateView() {
		if (inDropHeight == null || tubeLength == null || dropHeight == null
				|| matchWaterbox == null || ioConnectionLength == null
				|| diameter == null || installationSite == null
				|| constructionArea == null || addCoolantWeight == null) {
			Utils.showToastCenter(activity,
					getString(R.string.barcode_info_is_incomplete));
			return false;
		}
		return true;
	}


	@Override
	public HctResult getPwdResult(PwdEntity paramEntity,LocationEntity locationEntity, boolean isClounServer) throws Exception {
		HctResult result = new HctResult();
		result = controller.getBootPwd(paramEntity.phone, paramEntity.stripeCode,
				locationEntity.getmGpsLocation() ,
				locationEntity.getmBaseLocation(), locationEntity.getmWifiLocation(),locationEntity.getProvince_loc(),
				locationEntity.getCity_loc(), locationEntity.getProvince(), locationEntity.getCity(), locationEntity.getDistrict(), paramEntity.street,
				paramEntity.projectName, paramEntity.ownerName, paramEntity.ownerPhone, paramEntity.remark,
				paramEntity.industry, ioConnectionLength,
				inDropHeight, dropHeight, tubeLength,
				addCoolantWeight, diameter, matchWaterbox,
				installationSite, constructionArea, "",
				locationEntity.getmLatitude() + "",locationEntity.getmLongitude() + "", operationSite, isClounServer);
		return result;
	}

	public HctResult getPwdResult(PwdEntity paramEntity,LocationEntity locationEntity, boolean isClounServer,SYHotWaterMachineEntity syHotWaterMachineEntity) throws Exception {
		HctResult result = new HctResult();
		result = controller.getBootPwd(paramEntity.phone, paramEntity.stripeCode,
				locationEntity.getmGpsLocation() ,
				locationEntity.getmBaseLocation(), locationEntity.getmWifiLocation(),locationEntity.getProvince_loc(),
				locationEntity.getCity_loc(), locationEntity.getProvince(), locationEntity.getCity(), locationEntity.getDistrict(), paramEntity.street,
				paramEntity.projectName, paramEntity.ownerName, paramEntity.ownerPhone, paramEntity.remark,
				paramEntity.industry, syHotWaterMachineEntity.getIoConnectionLength(),
				syHotWaterMachineEntity.getInDropHeight(), syHotWaterMachineEntity.getDropHeight(),
				syHotWaterMachineEntity.getTubeLength(),syHotWaterMachineEntity.getAddCoolantWeight(),
				syHotWaterMachineEntity.getDiameter(), syHotWaterMachineEntity.getMatchWaterbox(),
				syHotWaterMachineEntity.getInstallationSite(), syHotWaterMachineEntity.getConstructionArea(), "",
				locationEntity.getmLatitude() + "",locationEntity.getmLongitude() + "",
				syHotWaterMachineEntity.getOperationSite(), isClounServer);
		return result;
	}
	
	
	
	/**
	 * 地暖工程 采暖形式
	 */
	private void initHeating_form() {
		
		final String[] items = getResources().getStringArray(
				R.array.heating_form);
		tubeLength = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_heating_form.setAdapter(adapter);

		spinner_heating_form.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					tubeLength = null;
				} else {
					tubeLength = items[arg2];
				}
				syHotWaterMachineEntity.setTubeLength(tubeLength);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});
	}
	/**
	 * 商用热水机-地暖工程：地暖管间距
	 */
	private void initFloor_heating_tube_spacing() {

		final String[] items = getResources().getStringArray(
				R.array.floor_heating_tube_spacing);
		inDropHeight = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_floor_heating_tube_spacing.setAdapter(adapter);

		spinner_floor_heating_tube_spacing.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					inDropHeight = null;
				} else {
					inDropHeight = items[arg2];
				}
				syHotWaterMachineEntity.setInDropHeight(inDropHeight);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：膨胀容器
	 */
	private void initExpansion_volume() {

		final String[] items = getResources().getStringArray(
				R.array.expansion_volume);
		diameter = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_expansion_volume.setAdapter(adapter);

		spinner_expansion_volume.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					diameter = null;
				} else {
					diameter = items[arg2];
				}
				syHotWaterMachineEntity.setDiameter(diameter);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：工程水箱容量
	 */
	private void initEngineering_tank_capacity() {

		spinner_engineering_tank_capacity.setPrompt(getString(R.string.tag_select_hint));

		final String[] items = getResources().getStringArray(
				R.array.engineering_tank_capacity);
		matchWaterbox = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_engineering_tank_capacity.setAdapter(adapter);

		spinner_engineering_tank_capacity.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					matchWaterbox = null;
				} else {
					matchWaterbox = items[arg2];
				}
				syHotWaterMachineEntity.setMatchWaterbox(matchWaterbox);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：机组安装位置
	 */
	private void initFHUnit_installation_position() {

		final String[] items = getResources().getStringArray(
				R.array.unit_installation_position);
		installationSite = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_unit_installation_position.setAdapter(adapter);

		spinner_unit_installation_position.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					installationSite = null;
				} else {
					installationSite = items[arg2];
				}
				syHotWaterMachineEntity.setInstallationSite(installationSite);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：建筑面积
	 */
	private void initBuilt_area() {

		final String[] items = getResources()
				.getStringArray(R.array.built_area);
		constructionArea = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_built_area.setAdapter(adapter);

		spinner_built_area.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					constructionArea = null;
				} else {
					constructionArea = items[arg2];
				}
				syHotWaterMachineEntity.setConstructionArea(constructionArea);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：地暖管外径
	 */
	private void initFloor_heating_tube_outer_diameter() {

		final String[] items = getResources().getStringArray(
				R.array.floor_heating_tube_outer_diameter);
		dropHeight = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_floor_heating_tube_outer_diameter.setAdapter(adapter);

		spinner_floor_heating_tube_outer_diameter.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					dropHeight = null;
				} else {
					dropHeight = items[arg2];
				}
				syHotWaterMachineEntity.setDropHeight(dropHeight);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：地暖管铺设方式
	 */
	private void initHeating_pipe_laying_method() {

		final String[] items = getResources().getStringArray(
				R.array.heating_pipe_laying_method);
		ioConnectionLength = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_heating_pipe_laying_method.setAdapter(adapter);

		spinner_heating_pipe_laying_method.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					ioConnectionLength = null;
				} else {
					ioConnectionLength = items[arg2];
				}
				syHotWaterMachineEntity.setIoConnectionLength(ioConnectionLength);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-地暖工程：地面面层构造
	 */
	private void initGround_surface_layer_structur() {

		final String[] items = getResources().getStringArray(
				R.array.ground_surface_layer_structur);
		addCoolantWeight = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_ground_surface_layer_structur.setAdapter(adapter);

		spinner_ground_surface_layer_structur.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					addCoolantWeight = null;
				} else {
					addCoolantWeight = items[arg2];
				}
				syHotWaterMachineEntity.setAddCoolantWeight(addCoolantWeight);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}



}
